﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using WpfForPrism区域.Views;

namespace WpfForPrism区域.ViewModels
{
    class MainWindowViewModel : BindableBase
    {
        /// <summary>
        ///  DelegateCommand 不是一个委托,继承了ICommand的一个类(相当于手搓MvvM当中自己创建的Command类)
        ///  ShowUCCmd 是具体的cmd
        /// </summary>
        public DelegateCommand<string> ShowUCCmd { get; set; }

        /// <summary>
        /// 区域管理
        /// </summary>
        private readonly IRegionManager _regionManager;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="regionManager"></param>
        public MainWindowViewModel(IRegionManager regionManager)
        {
            //将外部传来的
            this._regionManager = regionManager;
            //在构造函数中进行注册
            ShowUCCmd = new DelegateCommand<string>(ShowUCFunc);
        }

        //具体方法
        private void ShowUCFunc(string viewName)
        {
            //为指定区域添加具体的页面（实现切换）
            _regionManager.RequestNavigate("Content", viewName);            
        }

    }
}
